<script>
import {
    defineComponent,
    ref,
    watch,
    reactive,
    computed,
    nextTick,
    onMounted,
} from "vue";
import { getOrderList } from "~/api";
import { useRouter } from "vue-router";
export default defineComponent({
    setup(props) {
        const formData = reactive({
            pageNum: 0,
            pageSize: 20,
            total: 0,
            orderType: 1,
        });
        const loading = ref(false);
        const list = ref([]);

        const onSubmit = async () => {
            loading.value = true;
            try {
                const res = await getOrderList(formData);
                list.value = res.data.data.DayOrderList;
                formData.total = res.data.data.Total;
            } catch (error) {}
            loading.value = false;
        };
        const handleSizeChange = (val) => {
            formData.pageSize = val;
            formData.pageNum = 0;
            onSubmit();
        };
        const handleCurrentChange = (val) => {
            formData.pageNum = val - 1;
            onSubmit();
        };
        onMounted(() => {
            onSubmit();
        });
        return {
            formData,
            loading,
            list,
            onSubmit,
            handleSizeChange,
            handleCurrentChange,
        };
    },
});
</script>
<template>
    <div>
        <el-form ref="form" :model="formData" label-width="80px" :inline="true">
            <el-form-item label="排序">
                <el-select v-model="formData.orderType" placeholder="请选择" @change="onSubmit">
                    <el-option label="顺序" :value="0"> </el-option>
                    <el-option label="倒序" :value="1"> </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
                <el-button type="warning" @click="$refs.insert.show()">插入订单</el-button>
            </el-form-item>
        </el-form>
        <el-table ref="multipleTable" :data="list" v-loading="loading">
            <el-table-column prop="Id" width="80" label="#"> </el-table-column>
            <el-table-column prop="S" label="数量" width="110">
            </el-table-column>
            <el-table-column prop="SR1" label="显示收益率1" width="110">
            </el-table-column>
            <el-table-column prop="SR2" label="显示收益率2" width="110">
            </el-table-column>
            <el-table-column prop="SR3" label="显示收益率3" width="110">
            </el-table-column>
            <el-table-column prop="R" label="实际数量" width="110">
            </el-table-column>
            <el-table-column prop="RR1" label="实际收益率1" width="110">
            </el-table-column>
            <el-table-column prop="RR2" label="实际收益率2" width="110">
            </el-table-column>
            <el-table-column prop="RR3" label="实际收益率3" width="110">
            </el-table-column>
            <el-table-column prop="C" label="当前数量" width="110">
            </el-table-column>
            <el-table-column prop="Win1" label="1结果" width="110">
            </el-table-column>
            <el-table-column prop="Win2" label="2结果" width="110">
            </el-table-column>
            <el-table-column prop="Win3" label="3结果" width="110">
            </el-table-column>
            <el-table-column prop="Result" label="结算" width="110">
            </el-table-column>
            <el-table-column prop="Status" label="状态" width="110">
                <template #default="scope">
                    <p :style='{ color: [" #67c23a", "#67c23a", "#f56c6c", "#f56c6c"][scope.row.Status] }'>
                        {{ scope.row.Status <= 1 ? "未结算" : "已结算" }} </p>
                </template>
            </el-table-column>
            <el-table-column prop="Details1" label="详情1" width="380">
            </el-table-column>
            <el-table-column prop="Details2" label="详情2" width="380">
            </el-table-column>
            <el-table-column prop="Details3" label="详情3" width="380">
            </el-table-column>
            <el-table-column prop="CreatedAt" label="创建时间" min-width="160">
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="100">
                <template #default="scope">
                    <el-button type="success" size="small" @click="$refs.result.show(scope.row)">预计算</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-size="formData.pageSize" :total="formData.total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
        </el-pagination>
    </div>
    <insert-order ref="insert" @loadData="onSubmit" />
    <get-order-result ref="result" @loadData="onSubmit" />
</template>
<style lang="scss" scoped>
.el-pagination {
    padding: 15px;
    float: right;
}

.total {
    padding: 10px 0;
    font-size: 16px;
}

a {
    color: #1989fa;
}
</style>